package com.atguigu.ssyx.home.service.impl;

import com.atguigu.ssyx.client.product.ProductFeignClient;
import com.atguigu.ssyx.client.search.SkuFeignClient;
import com.atguigu.ssyx.client.user.UserFeignClient;
import com.atguigu.ssyx.home.service.HomeService;
import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.model.search.SkuEs;
import com.atguigu.ssyx.vo.user.LeaderAddressVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HomeServiceImpl implements HomeService {

    @Resource
    private UserFeignClient userFeignClient;

    @Resource
    private ProductFeignClient productFeignClient;

    @Resource
    private SkuFeignClient skuFeignClient;

    /**
     * 获取首页数据
     * @param userId
     * @return
     */
    @Override
    public Map<String, Object> homeDate (Long userId) {
        // 根据userId查询当前用户的提货地址信息
        /// 远程调用service-user模块的api获取数据
        LeaderAddressVo leaderAddressVo = userFeignClient.getUserAddressByUserId(userId);
        // 获取所有分类
        /// 远程调用service-product模块的api获取数据
        List<Category> categoryList = productFeignClient.findAllCategoryList();
        // 获取新人专享数据
        /// 远程调用service-product模块的api获取数据
        List<SkuInfo> newPersonSkuInfoList = productFeignClient.findNewPersonSkuInfoList();
        // 获取爆款数据
        /// 远程调用service-search模块的api获取数据-ES查询
        /// 通过score评分降序排序
        List<SkuEs> hotSkuList = skuFeignClient.findHotSkuList();

        // 封装数据到map集合
        Map<String, Object> result = new HashMap<>();
        result.put("leaderAddressVo", leaderAddressVo);
        result.put("categoryList", categoryList);
        result.put("newPersonSkuInfoList", newPersonSkuInfoList);
        result.put("hotSkuList", hotSkuList);
        return result;
    }
}
